package com.htl.exampro.exam.controller;

import com.htl.exampro.base.model.PageResult;
import com.htl.exampro.base.model.ServerResponse;
import com.htl.exampro.exam.pojo.query.ExamPageParam;
import com.htl.exampro.exam.pojo.vo.ExamVO;
import com.htl.exampro.exam.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 考试控制器
 */
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private ExamService examService;

    @GetMapping("/{id}")
    public ServerResponse<ExamVO> getExam(@PathVariable("id") Long id) {
        ExamVO exam = examService.getExam(id);
        return ServerResponse.success(exam);
    }

    @PostMapping("/page")
    public ServerResponse<PageResult<ExamVO>> getExamPage(@RequestBody ExamPageParam pageParam) {
        PageResult<ExamVO> result = examService.getExamPage(pageParam);
        return ServerResponse.success(result);
    }

    @PostMapping("")
    public ServerResponse<Void> createExam(@RequestBody ExamVO exam) {
        examService.createExam(exam);
        return ServerResponse.success();
    }

    @PutMapping("")
    public ServerResponse<Void> updateExam(@RequestBody ExamVO exam) {
        examService.updateExam(exam);
        return ServerResponse.success();
    }

    @DeleteMapping("/{id}")
    public ServerResponse<Void> deleteExam(@PathVariable("id") String id) {
        examService.deleteExam(id);
        return ServerResponse.success();
    }

    @PostMapping("/{examId}/question")
    public ServerResponse<Map<String, Object>> getExamInfo(@PathVariable("examId") String examId) {
        Map<String, Object> map = examService.getExamInfo(examId);
        return ServerResponse.success(map);
    }

}